import resolve from 'rollup-plugin-node-resolve';
import babel from 'rollup-plugin-babel';
import commonjs from 'rollup-plugin-commonjs';
import { merge } from 'lodash';
import {
    uglify
} from 'rollup-plugin-uglify'
import serve from 'rollup-plugin-serve';
import livereload from 'rollup-plugin-livereload';
const isProduction = process.env.NODE_ENV === 'productment'

const base = {
    input: 'src/index.js',
    output: {
        file: 'js/bundle.js',
        format: 'iife',
        name: 'land',
        sourceMap: !isProduction
    },
    plugins: [
        resolve(),
        babel({
            exclude: 'node_modules/**' // 只编译我们的源代码
        }),
        commonjs(),
    ]
};

const dev = {
    plugins: [
        serve({

            open: true, // 是否打开浏览器

            contentBase: './', // 入口html的文件位置

            historyApiFallback: true, // Set to true to return index.html instead of 404

            host: 'localhost',

            port: 8888

        }),
        livereload(),
    ],
}

const prod = {
    plugins: [
        uglify()
    ]
}

const config = merge(base, isProduction ? prod : dev)

export default config